package com.tpp.controller;

import com.tpp.entity.CinemaInfo;
import com.tpp.entity.Film;
import com.tpp.entity.FilmTime;
import com.tpp.service.CinemaService;
import com.tpp.service.FilmService;
import com.tpp.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@Controller
public class CCinema {
    @Autowired
    private CinemaService cinemaService;
    @RequestMapping("FindCinemaByAddress")
    @ResponseBody
    public Result FindCinemaByAddress(HttpServletRequest request){
        String address = request.getParameter("address")+"%";
        String[] cinemas=cinemaService.FindCinemaByAddress(address);
        System.out.println("address"+address);
        for(String x:cinemas){
            System.out.print(x+"|");
        }
        System.out.println(cinemas.length);
        Result result=new Result();
        result.setData(cinemas);
        return result;
    }
    @RequestMapping("show_cinema")
    public String showCinema(HttpServletRequest request, Model model){
        String Cinema_name = request.getParameter("Cinema_name");
        System.out.println("Cinema_name"+Cinema_name);
        CinemaInfo cinemaInfo=cinemaService.findCinemaByname(Cinema_name);
        List<String> onlineFilms=cinemaService.showAllFilmNameByCinema(Cinema_name);
        System.out.println("findCinemaByname:"+cinemaInfo);
        model.addAttribute("cinemaInfo",cinemaInfo);
        model.addAttribute("onlineFilms",onlineFilms);
        return "/static/cinema";
    }
    @RequestMapping("showAllCinemaByPlace")
    @ResponseBody
    public Result showAllCinemaByPlace(HttpServletRequest request){
        String place=request.getParameter("place");
        List<CinemaInfo> cinemas=cinemaService.showAllCinemaByPlace(place);
        Result result=new Result();
        if(cinemas.size()==0) {
            result.setData(cinemas);
            result.setMsg("查询错误");
            result.setStatus(1);
        }else {
            result.setData(cinemas);
            result.setMsg("查询成功");
            result.setStatus(0);
        }
        System.out.println(result.toString());
        return  result;
    }
    @RequestMapping("showAllCinemaByDesc")
    @ResponseBody
    public Result showAllCinemaByDesc(HttpServletRequest request){
        List<CinemaInfo> cinemas=cinemaService.showAllCinemaByDesc();
        Result result=new Result();
        if(cinemas.size()==0) {
            result.setData(cinemas);
            result.setMsg("查询错误");
            result.setStatus(1);
        }else {
            result.setData(cinemas);
            result.setMsg("查询成功");
            result.setStatus(0);
        }
        System.out.println(result.toString());
        return  result;
    }
    @RequestMapping("showAllCinemaByAsc")
    @ResponseBody
    public Result showAllCinemaByAsc(HttpServletRequest request){

        List<CinemaInfo> cinemas=cinemaService.showAllCinemaByAsc();
        Result result=new Result();
        if(cinemas.size()==0) {
            result.setData(cinemas);
            result.setMsg("查询错误");
            result.setStatus(1);
        }else {
            result.setData(cinemas);
            result.setMsg("查询成功");
            result.setStatus(0);
        }
        System.out.println(result.toString());
        return  result;
    }
    @RequestMapping("findFilmInfo_cinema")
    @ResponseBody
    public Result findFilmInfo(HttpServletRequest request){
        String Film_name = request.getParameter("Film_name");
        Film filmInfo=cinemaService.findFilmInfo(Film_name);
        Result result=new Result();
        if(filmInfo==null) {
            result.setData(filmInfo);
            result.setMsg("查询错误");
            result.setStatus(1);
        }else {
            result.setData(filmInfo);
            result.setMsg("查询成功");
            result.setStatus(0);
        }
        System.out.println(result.toString());
        return  result;
    }

}
